<template>
  <div>
    <f-search-form :more='true' @searchHandler='searchHandler' @exportHandler='exportHandler' :show-export-btn='true'>
      <f-search-form-item label='订单编号' name='orderNo' />
      <f-search-form-item label='业务员' name='saleManName' />
      <f-search-form-item label='部门' ref='dept' name='deptId' slot='advanced' type='select' :data='api.hyorder.listByCompanyId' valueKey='deptId' label-key='deptName' :params='queryParam' />
      <f-search-form-item label='发货日期' type='range' name='beginDate' />
      <f-search-form-item label='发货方式' type='select' slot='advanced' name='customBondType' :data='api.busCommon.sendType' />
      <f-search-form-item label='单位名称' name='customName' slot='advanced' />
    </f-search-form>
    <f-table ref='table' size='small' rowKey='orderDetailsId' :showSetting='false' setting-key='tasktodo_calculate_tab5' :tableColumns='orderDetailsColumns' :scroll='{x:true}' :multiple='false' :operator='operator' :params='queryParam' :api='api.hyOrderDetails' handler='hyCalApproveMonitorListHandler'>
      <span slot='sendType' slot-scope='text, record, index'>
       <a-tag color='#2db7f5' v-if='text==1'>现款</a-tag>
        <a-tag color='#FF0000' v-if='text==2'>预收款</a-tag>
        <a-tag color='#87d068' v-if='text==3'>资保金</a-tag>
        <a-tag color='purple' v-if='text==4'>全额资信</a-tag>
      </span>
      <span slot='deptType' slot-scope='text, record, index'>
        <a-tag color='#87d068' v-if='text=="ZS"'>招商</a-tag>
        <a-tag color='#108ee9' v-if='text=="ZY"'>自营</a-tag>
      </span>
      <span slot='saleType' slot-scope='text, record, index'>
           <a-tag color='#2db7f5' v-if='text=="CHA"'>销售</a-tag>
           <a-tag color='#FF0000' v-if='text=="CHC"'>退货</a-tag>
           <a-tag color='purple' v-if='text=="PZ"'>票折</a-tag>
       </span>
      <span slot='calculateState' slot-scope='text, record, index' @click='processImg(record,record.applyIncId)'>
            <a-tag color='pink' v-if='text==1'>办理中</a-tag>
            <a-tag color='#87d068' v-if='text==2'>已完成</a-tag>
      </span>
      <span slot='action' slot-scope='text, record'>
          <template>
            <a @click='$refs.caclulateApproveDrawer.showDrawer(record,record.applyIncId)'>查看</a>
             <a-divider type='vertical' />
          </template>
         <a-dropdown>
            <a class='ant-dropdown-link'>更多 <a-icon type='down' /></a>
            <a-menu slot='overlay'>
              <a-menu-item>
                <a href='javascript:;' @click='processImg(record,record.applyIncId)'>审批进度</a>
              </a-menu-item>
              <!--撤销流程重新审批-->
              <a-menu-item v-if='record.calculateState==1&& superAdmin'>
                <a href='javascript:;' @click='deleteProcessInstance(record.applyIncId,"hyCalculateProcDeleteHandler")'>撤销审批</a>
              </a-menu-item>
              <a-menu-item v-if='(superAdmin || allowHs) && record.calculateState==2'>
                <a href='javascript:;' @click='syncToReturn(record)'>同步数据到待回款</a>
              </a-menu-item>
              <a-menu-item v-if='superAdmin'>
                  <a href='javascript:;' @click='deleteProcessInstance(record.applyIncId)'>删除无效数据</a>
               </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
    </f-table>
    <process-image ref='processImg' v-if='processImageVisible' :visible.sync='processImageVisible' :processInstanceId='processInstanceId'></process-image>
    <caclulate-approve-drawer :allow-hs='allowHs' ref='caclulateApproveDrawer' @success='onLoad'></caclulate-approve-drawer>
  </div>
</template>
<script>

import api from "../../js/api"
import ProcessImage from "../../../flowable/process/process_image"
import { processMixins } from "@/core/mixins/processMixins"
import CaclulateApproveDrawer from "@/views/module/haiying/tasktodo/calculate/components/caclulate_approve_drawer"
import Vue from "vue"

export default {
  name: "Tab1",
  components: {
    CaclulateApproveDrawer,
    ProcessImage
  },
  mixins: [processMixins],
  data() {
    let me = this
    //操作按钮
    let operator = []
    //是否是商务角色
    let isHs = this.$store.state.user.roleInfo.isHs
    return {
      api: Object.assign(api, this.api),
      //列表初始化查询参数
      queryParam: {
        fileName: "已核算数据明细",
        processFinished: false,
        activeKey: 3,
        isFlp: 1
      },
      orderDetailsColumns: [],
      processInstanceId: "",
      processImageVisible: false,
      // 表头
      columns: [],
      allowHs:isHs==true,
      operator: operator
    }
  },
  created() {
    this.orderDetailsColumns = this.getColumns1()
  },
  mounted() {

  },
  methods: {
    onLoad() {
      this.$refs.table.refresh()
    },
    getColumns1() {
      let isCw = this.$store.state.user.roleInfo.isCw
      let isSw = this.$store.state.user.roleInfo.isSw
      let companyList = Vue.ls.get("companyList")
      return [
        {
          title: "序号",
          width: "50px",
          align: "center",
          fixed: "left",
          customRender: (text, record, index) => index + 1
        },
        {
          title: "账套",
          align: "center",
          ellipsis: true,
          width: "150px",
          fixed: "left",
          dataIndex: "companyName"
        },
        {
          title: "订单编号",
          align: "center",
          fixed: "left",
          dataIndex: "orderNo"
        },
        {
          title: "出库单号",
          align: "center",
          width: "130px",
          dataIndex: "outOrderNo"
        },
        {
          title: "销售类型",
          align: "center",
          width: "80px",
          dataIndex: "saleType",
          scopedSlots: { customRender: "saleType" }
        },
        {
          title: "业务类型",
          align: "center",
          width: "80px",
          dataIndex: "deptType",
          scopedSlots: { customRender: "deptType" },
          filters: [
            {
              text: "招商",
              value: "ZS"
            },
            {
              text: "自营",
              value: "ZY"
            }
          ],
          filterMultiple: false
        },
        {
          title: "发货日期",
          align: "center",
          width: "100px",
          dataIndex: "sendDate"
        },

        {
          title: "部门",
          align: "left",
          ellipsis: true,
          width: "120px",
          dataIndex: "deptName"
        },
        {
          title: "业务员",
          align: "left",
          ellipsis: true,
          width: "120px",
          dataIndex: "saleManName"
        },
        {
          title: "业务编码",
          align: "left",
          ellipsis: true,
          width: "120px",
          dataIndex: "businessCode"
        },
        {
          title: "单位名称",
          align: "left",
          ellipsis: true,
          width: "120px",
          dataIndex: "customName"
        },
        {
          title: "发货方式",
          align: "center",
          width: "100px",
          dataIndex: "sendType",
          scopedSlots: { customRender: "sendType" }
        },
        {
          title: "商品名称",
          align: "left",
          ellipsis: true,
          width: "140px",
          dataIndex: "drugsName"
        },
        {
          title: "规格",
          align: "left",
          ellipsis: true,
          length: 35,
          width: "150px",
          dataIndex: "drugsSpec"
        },
        {
          title: "批号",
          align: "left",
          ellipsis: true,
          width: "100px",
          dataIndex: "drugLotNo"
        },
        {
          title: "销售单价",
          align: "center",
          width: "80px",
          dataIndex: "salePrice"
        },
        {
          title: "数量",
          align: "center",
          width: "80px",
          type: 10,
          dataIndex: "saleNum"
        },
        {
          title: "销售金额",
          align: "center",
          width: "80px",
          type: 10,
          dataIndex: "saleAmount"
        },
        {
          title: "成本单价",
          align: "center",
          width: "80px",
          hidden: !isCw,
          type: 10,
          dataIndex: "costPrice"
        },
        {
          title: "成本金额",
          align: "center",
          width: "80px",
          hidden: !isCw,
          type: 10,
          dataIndex: "costAmount"
        },
        {
          title: "资保金应收",
          align: "center",
          width: "90px",
          type: 10,
          dataIndex: "customBond"
        },
        {
          title: "部门",
          align: "center",
          width: "90px",
          children: [
            {
              title: "结算价",
              align: "center",
              width: "80px",
              type: 10,
              dataIndex: "deptPrice"
            },
            {
              title: "结算标准",
              align: "center",
              width: "90px",
              type: 10,
              dataIndex: "deptRate"
            },
            {
              title: "部门费用",
              align: "center",
              width: "90px",
              type: 10,
              dataIndex: "deptSettleAmount"
            }
          ]
        },
        {
          title: "渠道商",
          align: "center",
          width: "120px",
          children: [
            {
              title: "结算价",
              align: "center",
              width: "80px",
              type: 10,
              dataIndex: "settlePrice"
            },
            {
              title: "结算标准",
              align: "center",
              width: "90px",
              type: 10,
              dataIndex: "settleRate"
            },
            {
              title: "发货结算金额",
              align: "center",
              width: "90px",
              hidden: !isCw,
              type: 10,
              dataIndex: "settleSendAmount"
            }, {
              title: "结算高开税金",
              align: "center",
              width: "90px",
              type: 10,
              hidden: !isCw,
              dataIndex: "customGapUpAmount"
            },
            {
              title: "结算金额",
              align: "center",
              width: "90px",
              type: 10,
              dataIndex: "settleAmount"
            }
          ]
        },
        {
          title: "商务经理",
          align: "center",
          width: "120px",
          children: [
            {
              title: "结算价",
              align: "center",
              width: "80px",
              type: 10,
              dataIndex: "settlePriceD"
            },
            {
              title: "结算标准",
              align: "center",
              width: "90px",
              type: 10,
              dataIndex: "settleRateD"
            },
            {
              title: "结算金额",
              align: "center",
              width: "90px",
              type: 10,
              dataIndex: "settleAmountD"
            }
          ]
        },
        {
          title: "片区服务商",
          align: "center",
          width: "120px",
          children: [
            {
              title: "结算价",
              align: "center",
              width: "90px",
              type: 10,
              dataIndex: "settlePriceC"
            },
            {
              title: "结算标准",
              align: "center",
              width: "90px",
              type: 10,
              dataIndex: "settleRateC"
            },
            {
              title: "结算金额",
              align: "center",
              width: "90px",
              type: 10,
              dataIndex: "settleAmountC"
            }
          ]
        },
        {
          title: "商务总负责人",
          align: "center",
          children: [
            {
              title: "结算价",
              align: "center",
              width: "80px",
              type: 10,
              dataIndex: "settlePriceE"
            },
            {
              title: "结算标准",
              align: "center",
              width: "90px",
              type: 10,
              dataIndex: "settleRateE"
            },
            {
              title: "结算金额",
              align: "center",
              width: "90px",
              type: 10,
              dataIndex: "settleAmountE"
            }
          ]
        },
        {
          title: "利润",
          align: "center",
          children: [
            {
              title: "超标准差额",
              align: "center",
              width: "90px",
              hidden: !(isCw || isSw),
              dataIndex: "taxRateDiff"
            },
            {
              title: "部门利润",
              align: "center",
              width: "90px",
              type: 10,
              hidden: !(isCw || isSw),
              dataIndex: "deptProfitAmount"
            },
            {
              title: "公司利润",
              align: "center",
              width: "90px",
              type: 10,
              hidden: !isCw,
              dataIndex: "profitAmount"
            },
            {
              title: "税收利润",
              align: "center",
              width: "90px",
              hidden: !isCw,
              type: 10,
              dataIndex: "taxProfitAmount"
            },
            {
              title: "产品利润",
              align: "center",
              width: "90px",
              type: 10,
              hidden: !isCw,
              dataIndex: "drugProfitAmount"
            },
            {
              title: "边际利润",
              align: "center",
              width: "90px",
              type: 10,
              hidden: !isCw,
              dataIndex: "bjProfitAmount"
            },
            {
              title: "支付开票税金",
              align: "center",
              width: "100px",
              type: 10,
              hidden: !isCw,
              dataIndex: "payInvoiceTaxAmount"
            }
          ]
        },
        {
          title: "制单人",
          align: "center",
          width: "100px",
          dataIndex: "nickName"
        },
        {
          title: "创建日期",
          align: "center",
          width: "100px",
          dataIndex: "createTime"
        },
        {
          title: "状态",
          align: "center",
          dataIndex: "calculateState",
          fixed: "right",
          scopedSlots: { customRender: "calculateState" },
          filters: [
            {
              text: "办理中",
              value: 1
            },
            {
              text: "已核算",
              value: 2
            }
          ],
          filterMultiple: false
        },
        {
          title: "操作",
          align: "center",
          fixed: "right",
          dataIndex: "action",
          width: "100px",
          scopedSlots: { customRender: "action" }
        }
      ]
    },
    //同步到回款数据
    syncToReturn(record) {
      this.http.confirm(this, {
        content: "确认同步数据吗?",
        url: this.api.hyOrderDetailsReturn.syncToReturn,
        data: {
          orderDetailsId: record.orderDetailsId
        },
        success: (me, data) => {
          this.$refs.table.refresh()
        }
      })
    },
    /**
     * 查询事件
     * @param searchParams
     */
    searchTable(searchParams) {
      this.queryParam = Object.assign(this.queryParam, searchParams)
      this.$refs.table.refresh(true, searchParams)
    }
  }
}
</script>
